package com.m3u8.db.model;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;

import static androidx.room.ForeignKey.CASCADE;

@Entity(tableName = "tb_ts", foreignKeys = @ForeignKey(entity = M3u8Model.class,
        parentColumns = "id",
        childColumns = "m3u8_id", onDelete = CASCADE, onUpdate = CASCADE), indices = @Index(value = {"m3u8_id"}))
public class TsModel implements Parcelable {


    public TsModel(String m3u8Url, String tsUrl, String localPath, long m3u8Id, int state, int tsTime) {
        super();
        this.m3u8Url = m3u8Url;
        this.tsUrl = tsUrl;
        this.localPath = localPath;
        this.m3u8Id = m3u8Id;
        this.state = state;
        this.tsTime = tsTime;
    }

    @Ignore
    public TsModel() {
        super();
    }

    @PrimaryKey(autoGenerate = true)
    private long id;

    @ColumnInfo(name = "m3u8Url")
    private String m3u8Url;

    @ColumnInfo(name = "tsUrl")
    private String tsUrl;

    @ColumnInfo(name = "localPath")
    private String localPath;

    @ColumnInfo(name = "m3u8_id")
    private long m3u8Id;

    @ColumnInfo(name = "state")
    private int state;

    @ColumnInfo(name = "tsTime")
    private int tsTime;

    @Ignore
    protected TsModel(Parcel in) {
        id = in.readInt();
        m3u8Url = in.readString();
        tsUrl = in.readString();
        localPath = in.readString();
        m3u8Id = in.readLong();
        state = in.readInt();
        tsTime = in.readInt();
    }

    public static final Creator<TsModel> CREATOR = new Creator<TsModel>() {
        @Override
        public TsModel createFromParcel(Parcel in) {
            return new TsModel(in);
        }

        @Override
        public TsModel[] newArray(int size) {
            return new TsModel[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(id);
        dest.writeString(m3u8Url);
        dest.writeString(tsUrl);
        dest.writeString(localPath);
        dest.writeLong(m3u8Id);
        dest.writeInt(state);
        dest.writeInt(tsTime);
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getM3u8Url() {
        return m3u8Url;
    }

    public void setM3u8Url(String m3u8Url) {
        this.m3u8Url = m3u8Url;
    }

    public String getTsUrl() {
        return tsUrl;
    }

    public void setTsUrl(String tsUrl) {
        this.tsUrl = tsUrl;
    }

    public String getLocalPath() {
        return localPath;
    }

    public void setLocalPath(String localPath) {
        this.localPath = localPath;
    }

    public long getM3u8Id() {
        return m3u8Id;
    }

    public void setM3u8Id(long m3u8Id) {
        this.m3u8Id = m3u8Id;
    }

    public void setState(int state) {
        this.state = state;
    }

    public int getState() {
        return state;
    }

    public void setTsTime(int tsTime) {
        this.tsTime = tsTime;
    }

    public int getTsTime() {
        return tsTime;
    }
}
